import 'package:dolqun_movies/StateManagement/ModelProvider.dart';
import 'package:dolqun_movies/UI/Pages/Models/CacheManagerModel.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:video_cache_manager/CacheManager.dart';

class DownloadPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => _DownloadPageState();
}

class _DownloadPageState extends State {
  @override
  Widget build(BuildContext context) {
    var cacheManager = ModelContainer.of<CacheManagerModel>(context).model.cacheManager;
    Widget buildingWidget;
    buildingWidget = Scaffold(
      appBar: AppBar(title: Text("چۈشۈرۈلمىلەر"),),
      body: cacheManager.videos.isEmpty ? Center(child: Text("Empty"),) : ListView(
          children: cacheManager.videos.map((item) => _buildItem(item)).toList()
      ),
    );
    buildingWidget = Directionality(
      child: buildingWidget,
      textDirection: TextDirection.rtl,
    );
    buildingWidget = ListTileTheme(
      child: buildingWidget,
      iconColor: Colors.blue,
      textColor: Colors.blue,
    );
    return buildingWidget;
  }

  Widget _buildItem(VideoManifest item) {
    return ListTile(
      title: Text(item.name),
      subtitle: Text(item.name),
      leading: Icon(Icons.movie),
      trailing: Wrap(
        children: [
          IconButton(
            icon: Icon(Icons.delete),
            onPressed: (){
              setState(() {

              });
            },
          )
        ],
      ),
      onTap: (){},
    );
  }
}